package com.angcyo.selenium.auto.action

import com.angcyo.selenium.auto.BaseControl
import com.angcyo.selenium.auto.parse.HandleResult
import com.angcyo.selenium.bean.ActionBean
import org.openqa.selenium.WebElement

/**
 * Email:angcyo@126.com
 * @author angcyo
 * @date 2020/12/31
 */
class ForwardAction : BaseAction() {
    override fun interceptAction(control: BaseControl, action: String?): Boolean {
        return action?.startsWith(Action.ACTION_FORWARD) == true
    }

    override fun runAction(
        control: BaseControl,
        element: WebElement,
        actionBean: ActionBean,
        action: String
    ): HandleResult {
        return element.actionResult(control) { elementStr ->
            (control.driver?.navigate()?.run {
                forward()
                true
            } ?: false) to "前进网页[${control.driver?.currentUrl}]"
        }
    }
}